CREATE TABLE [dbo].[tb_barrios]
(
[idBarrio] [int] NOT NULL IDENTITY(1, 1),
[Barrio] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Localidad] [int] NOT NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updateBarrio] ON [dbo].[tb_barrios] 
FOR UPDATE
AS

if (update(idBarrio)) begin
	UPDATE tb_Edificios
	SET barrio = (SELECT idBarrio from inserted)
	WHERE barrio in (Select idBarrio from deleted)
end
GO
ALTER TABLE [dbo].[tb_barrios] ADD CONSTRAINT [PK_tb_barrios] PRIMARY KEY NONCLUSTERED  ([idBarrio]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[tb_barrios] WITH NOCHECK ADD CONSTRAINT [FK_tb_barrios_tb_Localidades] FOREIGN KEY ([Localidad]) REFERENCES [dbo].[tb_Localidades] ([idLocalidad])
GO
ALTER TABLE [dbo].[tb_barrios] NOCHECK CONSTRAINT [FK_tb_barrios_tb_Localidades]
GO
